package com.mk.common.util;

import java.awt.Color;

import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.junit.Test;

public class CalcDemo
{
	/**
	 * 乘
	 */
	@Test
	public void test1() {
		System.out.println( 2<<1 ); //4
		System.out.println( 3<<1 ); //6
		System.out.println( 5<<1 ); //10
	}
	
	/**
	 * 除
	 */
	@Test
	public void test2() {
		System.out.println( 2>>1 ); //1
		System.out.println( 3>>1 ); //1
		System.out.println( 5>>1 ); //2
	}
	
	/**
	 * 两值交换: 位运算
	 */
	@Test
	public void test3() {
		int x = 1, y = 2;
		x = x^y;
		y = x^y;
		x = x^y;
		
		System.out.println("x: "+x+", y: "+y); //x: 2, y: 1
	}
	/**
	 * 两值交换: 加减运算
	 */
	@Test
	public void test4() {
		int x = 1, y = 3;
		x = x + y;
		y = x - y;
		x = x - y;
		
		System.out.println("x: "+x+", y: "+y); //x: 3, y: 1
	}
	
	@Test
	public void test5() {
		int a = 1000, b= 2000;
		a = a^b;
		b = a^b;
		a = a^b;
		
		System.out.println("a="+a+", b="+b);
	}
	
	@Test
	public void test6() {
		Double num = (double) 1;
		System.out.println(num); // 1.0
	}
	
	@Test
	public void test7() {
		Double num1 = 2.0;
		Double num2 = 2.0;
		System.out.println(num1==num2); // false
	}
	
	@Test
	public void test8() {
		Double num1 = 0.1;
		System.out.println(num1==num1.intValue()); //true
	}
	
	@Test
	public void testHex() {
		String hex = "#d5a6bd";
		String hexCode = hex.replace("#","");
		
		int intValue = Integer.parseInt(hexCode, 16); // 14001853
		int red = (intValue >> 16) & 0xFF;
		int green = (intValue >> 8) & 0xFF;
		int blue = intValue & 0xFF;
		
		
//		 213, 166, 189
		System.out.println(red+", "+green+", "+blue);
	}
	
	@Test
	public void testIndexColors() {
		System.out.println(IndexedColors.CORNFLOWER_BLUE.getIndex() ); // 24
	}
	
	@Test
	public void testColors() {
		Color color = new Color(213, 166, 189);
		XSSFColor xssfColor = new XSSFColor(color);
	}
	
}
